package com.swyc.osschat.Test.LambdaTest.Controller;

import java.math.BigDecimal;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;

import com.swyc.osschat.Test.LambdaTest.Bean.Student;

/**
 * @author zhaol@yunrong.cn
 * @version V2.1
 * @since 2.1.0 2019/8/9 10:22
 */
public class PredicateTest {
    public static void main(String[] args) {
        Predicate<Integer> predicate = x -> x>185;
        Student student = new Student("9龙", 23, 175);
        System.out.println("9龙的身高高于185吗？：" + predicate.test(student.getStature()));
        Consumer<String> consumer = System.out::println;
        consumer.accept("命运由我不由天");
        Function<Student, String> function = Student::getName;
        String name = function.apply(student);
        System.out.println(name);
        Supplier<Integer> supplier = () -> Integer.valueOf(BigDecimal.TEN.toString());
        System.out.println(supplier.get());
        UnaryOperator<Boolean> unaryOperator = uglily -> !uglily;
        Boolean apply2 = unaryOperator.apply(false);
        System.out.println(apply2);
        BinaryOperator<Integer> operator = (x, y) -> x * y;
        BinaryOperator<BigDecimal> operator1 = (x,y)->x.add(y);
        BigDecimal bigDecimal = new BigDecimal("0.0000");
        bigDecimal = operator1.apply(new BigDecimal(99.99),new BigDecimal(3.33));
        Integer integer = operator.apply(2, 3);
        System.out.println(integer+"<>"+bigDecimal);
        test(() -> "我是一个演示的函数式接口");
    }

    /**
     * 演示自定义函数式接口使用
     *
     * @param worker
     */
    public static void test(Worker worker) {
        String work = worker.work();
        System.out.println(work);
    }
    public interface Worker {
        String work();
    }
}
